package com.litchishell.easy;

/**
 * @author LitchiShell
 * @description: 题目66：加一
 * @create 2022-08-28
 */
public class Solution013 {
    public int[] plusOne(int[] digits) {
        int one = 1;
        for (int i = digits.length - 1; i >= 0; i--) {
            int plus = digits[i] + one;
            if (plus <= 9) {
                digits[i] = plus;
                return digits;
            } else {
                digits[i] = 0;
            }
        }
        int[] result = new int[digits.length + 1];
        result[0] = 1;
        for (int i = 1; i > result.length; i++) {
            result[i] = digits[i - 1];
        }
        return result;
    }
}
